package com.cysyz.web.modules.base.lock.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LockAbleEntityCheckAspect {

    //声明前置通知  
    //@Before("pointCutMethod()")
    public void doBefore(JoinPoint jp) {


    }  
  
    //声明后置通知  
    //@AfterReturning(pointcut = "pointCutMethod()", returning = "result")
    public void doAfterReturning(String result) {  
        System.out.println("后置通知");  
        System.out.println("---" + result + "---");  
    }  
  
    //声明例外通知  
    //@AfterThrowing(pointcut = "pointCutMethod()", throwing = "e")
    public void doAfterThrowing(Exception e) {  
        System.out.println("例外通知");  
        System.out.println(e.getMessage());  
    }  
  
    //声明最终通知  
    //@After("pointCutMethod()")
    public void doAfter() {  
        System.out.println("最终通知");  
    }  
  
    //声明环绕通知  
    /*@Around("pointCutMethod()")*/
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {

//        Signature signature = pjp.getSignature();
//        MethodSignature methodSignature = (MethodSignature) signature;
//        Method method = methodSignature.getMethod();
//
//        if (!BaseController.class.isAssignableFrom(method.getDeclaringClass())) {
//            throw new IllegalStateException("BusinessLogPersistAspect can only intercept the Controller class which inherit from BaseController");
//        }
//
//        ModuleFunction moduleFunction = MyReflectionUtils.getAnnotation(method, ModuleFunction.class);
//        if(methodNameFilter.filter(method.getName()) && moduleFunction != null && moduleFunction.moduleFunctionType() == ModuleFunctionType.NORMAL) {
//            if (!method.isAnnotationPresent(BusinessLogInfo.class)) {
//                throw new IllegalStateException("the Controller which want to be businesslogable must be @BusinessLogInfo annotationed:[" + method.getDeclaringClass().getName() + "." + method.getName() + "]" + ". if do not want to let this method be loged, you can config business_log_method.properties file.");
//            }
//
//            BusinessLogInfo businessLogAnnotation = method.getAnnotation(BusinessLogInfo.class);
//
//            SysBusinessLog businessLog = new SysBusinessLog();
//            businessLog.setOperationName(businessLogAnnotation.operationName());
//            businessLog.setBusinessLogType(businessLogAnnotation.businessLogType());
//
//            SysUser currentLoginAdmin = SessionData.getCurrentLoginSysUser();
//            businessLog.setOperator(currentLoginAdmin);
//            businessLog.setOperateDate(new Date());
//            businessLog.setExtraMessage((String) ServletActionContext.getContext().get(SysConstants.BusinessLog.BUSINESSLOG_MESSAGE));
//            this.save(businessLog);
//            ServletActionContext.setBusinessLog(businessLog);
//        }

        Object o = pjp.proceed();

        return o;
    }  
} 